<?php
if( empty( $_SESSION ) )
{
	session_start();	
}
header("Content-Type: text/html; charset=utf-8",true);

include("fckeditor.php");
include_once("../../includes/restrito.php");
include_once("../models/cls.expediente.php");

$oExpediente = new expediente();

switch( isset( $_GET["acao"] ) )
{
	case "editar" :
		$oExpediente->select( $_GET["id"] );
		break;
		
	case "excluir" :
		$oExpediente->delete( $_GET["id_delete"], "../views/frm.expediente.php" );
		break;				
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EDIÇÃO</title>
<link rel="stylesheet" type="text/css" href="../../includes/sistema.css"/>
<script type="text/javascript" src="../../includes/jquery.js"></script>
<script type="text/javascript" src="../../includes/jquery.mask.js"></script>
<script>
jQuery(function($){
	$("#ano").mask("999");
	$("#data").mask("99/99/9999");
})

function _excluir(id)
{
	if(confirm("Por favor, confirme há remoção!"))
	{
		window.location.href="frm.expediente.php?id_delete=" + id + "&acao=excluir";
	}	
}

function _dataFilter(ano)
{
	window.location.href="frm.expediente.php?ano=" + ano + "&acao=dataFilter";
}

function _salvar(){

	if(document.frm.id_idioma.value=="")
	{
		alert("Por favor, informe o idioma desta edição!");
		document.frm.id_idioma.focus();
		return;
	}
	if(document.frm.titulo.value=="")
	{
		alert("Por favor, informe o título do expediente!");
		document.frm.titulo.focus();
		return;
	}
	if(document.frm.descricao.value=="")
	{
		alert("Por favor, informe a descrição do expediente!");
		document.frm.descricao.focus();
		return;
	}
	document.frm.submit();
}
</script>
</head>
<body>
<div id="content">
    <h2>Expediente</h2>
    <hr size="1" noshade="noshade">
    	<form name="frm" method="post" action="../controllers/ctl.expediente.php">
        
          <table width="100%" border="0" align="center">
            <tr>
              <td width="83%">Título:
              <input name="titulo" type="text" class="form100pc" value="<?php echo $oExpediente->titulo; ?>" /></td>
              <td width="17%">
              Idioma:
                <br />
                <select name="id_idioma" class="form200px">
                <?php echo $oExpediente->select_idioma(); ?>
                </select>
              </td>
            </tr>
            <tr>
              <td colspan="2">
              
			Descrição:
			  <br />
			  <?php
            $sBasePath = $_SERVER['PHP_SELF'] ;
            $sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "editor" ) ) ;
            
            $oFCKeditor = new FCKeditor('descricao',200);
            $oFCKeditor->BasePath = $sBasePath;
			if( ! empty( $oExpediente->descricao ) )
			{
            	$oFCKeditor->Value = $oExpediente->descricao;
			}
			else
			{
				$oFCKeditor->Value = "&nbsp;";
			}
            $oFCKeditor->Create();
            ?>              
            
            </td>
            </tr>
            <tr>
              <td colspan="2"><input type="button" name="btnSalvar" value="SALVAR" class="formButton" onClick="_salvar()" />
              <input type="hidden" name="id" value="<?php echo $oExpediente->id; ?>" /></td>
            </tr>
          </table>
        <hr size="1" noshade="noshade">
            
<?php
$cor=true;
$aExpediente = $oExpediente->select_expediente();

echo '<table width=100%>';
echo '<th align="left">TÍTULO</th>';
echo '<th align="center">IDIOMA</th>';
echo '<th align="center">EDITAR</th>';
echo '<th align="center">EXCLUIR</th>';

foreach($aExpediente as $sItem) // VARRE A LISTA E IMPRIME OS ÍNDICES DA COLEÇÃO
{
	// ALTERNA AS CORES DA LINHA DA TABELA A CADA REGISTRO IMPRESSO
	if($cor)
	{
		$tdcor = "#F4F4F4"; //CINZA CLARO
		$cor=false;
	}
	else{
		$tdcor = "#FFFFFF"; //BRANCO
		$cor = true;
	}
	
	echo '<tr bgcolor="'. $tdcor .'">';
	
	echo '<td align="left">' . $sItem["titulo"] . '</td>';
	
	switch( $sItem["sigla"] )
	{
		case "BR" :
			$icon = "br.gif";
			break;
		case "ES" :
			$icon = "es.gif";
			break;
		case "FR" :
			$icon = "fr.gif";
			break;
		case "DE" :
			$icon = "de.gif";
			break;
		case "US" :
			$icon = "us.gif";
			break;
		case "NL" :
			$icon = "nl.gif";
			break;
		case "IT" :
			$icon = "it.gif";
			break;
		default :
			$icon = "world.gif";
			break;
	}
	
	echo '<td width="15%" align="center"><img src="../imagens/' . $icon . '" border="0"></td>';
	echo '<td width="15%" align="center"><a href="frm.expediente.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" border="0"></a></td>';
	echo '<td width="15%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ');"><img src="../imagens/excluir.png" border="0"></a></td>';
	echo '</tr>';
}
echo '</table>';
?> 

</div>
</body>
</html>